package servlet;

import com.google.gson.Gson;
import org.nf.demo.entity.User;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.PrintWriter;

/**
 * @Author czl
 * @Date 2024-04-19
 */
@WebServlet("/UserServlet")
public class UserServlet extends HttpServlet {
    @Override
    protected void service(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {

        resp.setCharacterEncoding("UTF-8");
        resp.setContentType("application/json; charset=UTF-8");

        User user = new User("大傻椿",18,"女");

        String json = new Gson().toJson(user);
        PrintWriter out = resp.getWriter();



        out.print(json);
        out.flush();
        out.close();
    }
}
